﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/include/taglibs.jsp"%>
<%@ include file="/common/include/dictNames.jsp"%>
<%@ include file="/common/include/pageExpires.jsp"%>
<%@ page import="com.kylin.module.shop.orm.*,com.kylin.common.dict.orm.*" %>
<%
    String currLanguage = request.getParameter("language");
    if(currLanguage == null)
        currLanguage = sessionLocale.toString();
%>

<br>
<script language="javaScript">
	function checkSubmit(nextdo)
	{
		if(document.tradeForm.title.value == "")
		{
			alert("标题不允许为空");
			return false;
		}
		document.tradeForm.nextdo.value=nextdo;
		document.tradeForm.submit();
	}
</script>
<form name="tradeForm" action="/admin/shop/manageTrade.do?CMD=tradeAdd" method="post">
<input type="hidden" name="nextdo" value="addSucc">
<table width="90%" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td height="30" class="ms02">&nbsp;&nbsp;</td>
      </tr>
	   <tr>
	   		  商城管理→供求信息维护→供求信息添加
              <td bgcolor="CDCDCD" height="1"></td>
        </tr>
    </table>
      <br>
<mytag:MyActionMsg />
      <table width="90%" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td align="left">信息类型：</td>
          <td>
             <input name="type" type="radio" value="<%=Content.TYPE_SELL%>" checked>出售
             <input name="type" type="radio" value="<%=Content.TYPE_BUY%>">收购
           </td>
        </tr>
        <tr>
          <td align="left">投放语言：</td>
          <td>      
<script>
function changeLanguage(lang){
    location.replace('/admin/shop/tradeAdd.jsp?language='+lang);
}
</script>
        <mytag:national name="language" onchange="changeLanguage(this.value)" 
             notEmpty="true" value="<%=currLanguage%>" dictName="<%=Constants.SYSLANGUAGE%>" />
              <br> 
          </td>
        </tr>
        <tr>
          <td align="left">投放国家：</td>
          <td>
      		    <mytag:national name="country" notEmpty="true" value="<%= sessionLocale.toString() %>" dictName="<%=Constants.ALLCOUNTRY%>"/>
           </td>
        </tr>
        <tr>
          <td align="left">标题：</td>
          <td><input class="input01" name="title" type="text" size="40">
              <br> 
          </td>
        </tr>
        <tr>
          <td align="left">描述：</td>
          <td>
	<%@ taglib uri="http://fckeditor.net/tags-fckeditor" prefix="FCK" %>
	<script type="text/javascript" src="/FCKeditor/fckeditor.js"></script>
	<FCK:editor id="content" basePath="/common/webeditor/"
		autoDetectLanguage="false"
		defaultLanguage="<%=JspHelper.getFCKLang("zh_CN") %>"
		imageUploadURL="/editor/filemanager/upload/simpleuploader?Type=Image"
		linkUploadURL="/editor/filemanager/upload/simpleuploader?Type=File"
		flashUploadURL="/editor/filemanager/upload/simpleuploader?Type=Flash">
	</FCK:editor>
          </td>
        </tr>
        <tr>
          <td align="left">数量：</td>
          <td>
            <input class="input01" name="quantity" type="text" size="10">
              单位<mytag:select name="unitId" language="<%=currLanguage%>" dictName="计量单位"/>
         </td>
        </tr>
        <tr>
          <td align="left">包装：</td>
          <td><input class="input01" name="ppackage" type="text" size="26"></td>
        </tr>
        <tr>
          <td align="left">价格/术语条件：</td>
          <td><input class="input01" name="price" type="text" size="10">
            币种<mytag:select name="currencyId" language="<%=currLanguage%>" dictName="币种"/>
          </td>
        </tr>
        <tr>
          <td align="left">联系人：</td>
          <td><input class="input01" name="contact" type="text" size="26"></td>
        </tr>
        <tr>
          <td align="left">电话：</td>
          <td>
            <input class="input01" name="phoneCountry" type="text" size="10">
            -
            <input class="input01" name="phoneArea" type="text" size="10">
            -
            <input class="input01" name="phone" type="text" size="10">
          </td>
        </tr>
        <tr>
          <td align="left">传真：</td>
          <td>
          <input class="input01" name="faxCountry" type="text" size="10">
            -
            <input class="input01" name="faxArea" type="text" size="10">
            -
            <input class="input01" name="fax" type="text" size="10">
          </td>
        </tr>
        <tr>
          <td align="left">邮箱：</td>
          <td><input class="input01" name="email" type="text" size="26"></td>
        </tr>
        <tr>
          <td align="left">所属分类：</td>
          <td>
<script>
function isParentCat(theSelect){
	for (var i = 0; i < theSelect.length; i++) {
		if (theSelect.options[i].selected == true 
			&& theSelect.options[i].pid =="") {
			return true;
		}
	}
	return false;
}
</script>
         <% 
            //构造 产品类别下拉菜单
    	    List maincatproduct = MemObjFactory.getDict("产品类别",currLanguage);
            boolean disableSelectParent = true; 
            out.println(getCatProductSelect(maincatproduct,"catProductId",disableSelectParent,currLanguage));
        %>
              </td>
        </tr>
        <tr>
          <td align="left">有效期：</td>
          <td>
			  <mytag:CalendarInput name="duedate" id="duedate" imgId="duedate_img" />
          </td>
        </tr>
        <tr align="center">
          <td height="50" colspan="2">
          	<input type="button" name="Submit" onclick="checkSubmit('tradeAddSucc')" value="保存并继续添加">
          	<input type="button" name="Submit" onclick="checkSubmit('tradeList')" value="保存并返回列表">
          </td>
        </tr>
      </table>
</form>

<%!

	/**
	 * 产生产品类别下拉菜单的html源码
	 * @param maincatproduct 产品类别数据
	 * @param selectName 下拉菜单名
	 * @param disableSelectParent  是否禁止选择父级菜单
	 * @return
	 */
	public  String getCatProductSelect(List maincatproduct, String selectName, boolean disableSelectParent,String language) {
		StringBuffer sb1 = new StringBuffer();
		StringBuffer sb2 = new StringBuffer();
		if (maincatproduct != null)
			for (int i = 0; i < maincatproduct.size(); i++) {
				Dict dict = (Dict) maincatproduct.get(i);
				String dictName = dict.getName();
				dictName = dictName.replaceAll("'", "`");
				if(dict.getDescription()==null)
					dict.setDescription("");
				dict.setDescription(dict.getDescription().replaceAll("'", "`"));
				dict.setDescription(dict.getDescription().replaceAll("\n", ""));
				dict.setDescription(dict.getDescription().replaceAll("\r", ""));
				if(!"zh_CN".equals(language) && !"".equals(dict.getDescription()))
				    dictName = dictName + " ("+dict.getDescription()+")";
				if (dict.getParent() == null) {
					if (sb1.length() > 1)
						sb1.append(",");
					sb1.append("\n  new SubSelectObj('").append(dict.getId()).append("','");
					sb1.append("").append("','");
					sb1.append(dictName).append("')");
				} else {
					if (sb2.length() > 1)
						sb2.append(",");
					sb2.append("\n  new SubSelectObj('").append(dict.getId()).append("','");
					sb2.append(dict.getParent().getId()).append("','");
					sb2.append(dictName).append("')");
				}
			}
		String selectId = com.kylin.common.util.UUID.create("select");
		StringBuffer content = new StringBuffer();
		content.append("  <select name=\"");
		content.append(selectName);
		content.append("\" id=\"");
		content.append(selectId);
		content.append("\"  class=\"input01\" ");
		if (disableSelectParent)
			content.append("       onchange=\"checkCascadSelect(this)\"  ");
		content.append("    > ");
		content.append("     <option value=''>-- 选择产品类别 ??--</option>");
		content.append("  </select>");
		content.append("  <script src=\"/script/kylin.js\"></script>");
		content.append("  <script>");
		content.append("      \n var "+selectName+"ParentArray = new Array(" + sb1 + ");  ");
		content.append("      \n var "+selectName+"SubArray = new Array(" + sb2 + ");     ");
		content.append("      \n var theCatSelect =  document.getElementById(\""+selectId+"\");     ");
		content.append("      \n setCascadSelect("+selectName+"ParentArray,"+selectName+"SubArray,theCatSelect);  ");
		content.append("   </script>  ");
		return content.toString();
	}

%>
